package com.forestar.xzk.commonlibrary;

import android.app.Activity;
import android.view.KeyEvent;

/**
 * created by  xzk
 * 2020/7/10   11:59
 * 说明:  双击返回
 */
public class DoubleBackUtil {
    private long lastMillis = 0L;

    public boolean doubleToBack(int keyCode, Activity activity){
        if(keyCode == KeyEvent.KEYCODE_BACK){
            long timeMillis = System.currentTimeMillis();
            if(timeMillis - lastMillis>2_000L){
                ToastUtil.showShort(activity,"再按一次，退出程序");
                lastMillis = timeMillis;
                return true;
            }else{
                //判断连续点击，执行对应操作  启动退出程序
//                ToastUtil.showToastShort(activity,"启动退出程序");
//                return true;
            }
        }
        return false;
    }

}
